package chap6;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ExceptionDemo2 {
	public static void main(String args[]){
		String[] week={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
		try{
			System.out.println("Enter an index number (0~6):");
			BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
			String input = new String(stdin.readLine());
			try{
				int index = Integer.parseInt(input);
				System.out.println(index+" is "+ week[index]);
			}
			catch(NumberFormatException e){
				//e.printStackTrace();
				System.out.println("Index should be an integer");
			}
			catch(IndexOutOfBoundsException e){
				System.out.println("Indext must between 0 and 6");
			}			
		}
		catch(IOException e){
			System.out.println(e);
		}
		finally{
			System.out.println("End of Program");
		}
	}
}
